package planit.controller.impl;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JOptionPane;

import planit.model.Group;
import planit.model.Model;
import planit.view.GroupDialog;

@SuppressWarnings("serial")
public class CreateGroupController extends AbstractAction {
	private Model model;

	public CreateGroupController(Model model) {
		this.model = model;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		GroupDialog dialog = (GroupDialog)this.getValue("GroupDialog");

		if (dialog.getGroupName().length() > 0) {
			Group g = new Group(dialog.getGroupName());
			g.setDescription(dialog.getGroupDescription());
			model.getSchedule().addGroup(g);
			dialog.dispose();
		} else {
			JOptionPane.showMessageDialog(null,
					"You have to enter the name of the group", "Error",
					JOptionPane.WARNING_MESSAGE);
		}
	}

}
